# -*- coding: utf-8 -*-
# @Time : 2021/9/8 17:25
# @Author : 唐宁
# @Site : 
# @File : FileService.py
# @Software: PyCharm
import time

from fastapi import UploadFile

from util.FileHandler import get_file_path


class FileService:

    @classmethod
    async def saveFileToNative(cls, file: UploadFile):
        start = time.time()
        # 读取文件
        res = await file.read()
        # 生成文件存储路径
        file_path = get_file_path(file.filename)
        # 写入文件
        with open(file_path, "wb") as f:
            f.write(res)
            # 返回文件地址
            return file_path
